package com.bit.mybatis.mapper;

import com.bit.mybatis.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

//    @Results({
//            @Result(),
//            @Result(),
//            @Result(),
//            @Result()
//    })
    @Select("select * from user_info")
    List<UserInfo> selectAll();

    @Select("select * from user_info where id = #{id}")
    UserInfo selectAllById(Integer id);

    @Select("SELECT * FROM `user_info` where username=#{userName} and `password` = #{password} ")
    List<UserInfo> selectByNameAndPassword(@Param("password") String password, @Param("userName") String username);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info (username, `password`, age) VALUES (#{username}, #{password}, #{age})")
    Integer insertUser(UserInfo userInfo);

    @Delete("delete from user_info where id = #{id}")
    void delete(Integer id);

    @Update("update uer_info set username = #{username} where id = #{id}")
    void update(UserInfo userInfo);
}
